package dao;

import hibernateUtils.HibernateUtil;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import beans.ItemProovedorBean;

public class HibernateItemProovedorDAO {
	private static HibernateItemProovedorDAO instancia;
	private static SessionFactory sf;

	private HibernateItemProovedorDAO() {

	}

	public static HibernateItemProovedorDAO getInstancia() {
		if (instancia == null) {
			sf = HibernateUtil.getSessionFactory();
			instancia = new HibernateItemProovedorDAO();
		}
		return instancia;
	}

	public void grabarItemProovedor(ItemProovedorBean fb) {
		Session session = sf.openSession();
		session.beginTransaction();
		session.save(fb);
		session.flush();
		session.getTransaction().commit();
		session.close();
	}

	public ItemProovedorBean buscarItemProovedor(ItemProovedorBean fb) {
		Session session = sf.openSession();
		ItemProovedorBean f = (ItemProovedorBean) session.get(
				ItemProovedorBean.class, fb.getIdItemProovedor());
		session.close();
		return f;
	}
}
